package com.qfedu.dao.impl;

import com.qfedu.dao.IItemDao;
import com.qfedu.entity.Item;
import com.qfedu.utils.JDBCUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class ItemDaoImpl implements IItemDao {
    @Override
    public int insertItem(String oid, int pid, double imoney, int inum) throws SQLException {
        QueryRunner queryRunner = new QueryRunner();
        int update = queryRunner.update(JDBCUtil.getConnection(), "insert into item(oid,pid,imoney,inum) values (?,?,?,?)", oid, pid, imoney, inum);
        return update;
    }

    @Override
    public List<Item> queryItemList(String oid) throws SQLException {
        return new QueryRunner(JDBCUtil.getDataSource()).query("select * from item where oid = ?",new BeanListHandler<Item>(Item.class),oid);
    }
}
